/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package interfaz;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.swing.JFileChooser;

/**
 *
 *
 * Interfaz gráfica para la configuración de la ubicación de Xilinx
 *
 * Created on 04-jun-2010, 16:02:42
 */
public class GUIConfig extends javax.swing.JDialog {
    
    private String rutaXilinxISE;
    private String rutaXilinxEDK;
    private String rutaXilinxPLANAHEAD;
    private boolean cierre;

    /** Creates new form GUIConfig */
    public GUIConfig(java.awt.Frame parent, boolean modal,String rutaISE,String rutaEDK, String rutaPLANAHEAD) {
        super(parent, modal);
        rutaXilinxISE=rutaISE;
        rutaXilinxEDK=rutaEDK;
        rutaXilinxPLANAHEAD=rutaPLANAHEAD;
        initComponents();
        cierre=false;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _lbl_HomeXilinx_ISE = new javax.swing.JLabel();
        _txt_HomeXilinx_ISE = new javax.swing.JTextField();
        _btn_HomeXilinx_ISE = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        _btnOK = new javax.swing.JButton();
        _btnCancelar = new javax.swing.JButton();
        _txt_HomeXilinx_EDK = new javax.swing.JTextField();
        _lbl_HomeXilinx_EDK = new javax.swing.JLabel();
        _btn_HomeXilinx_EDK = new javax.swing.JButton();
        _txt_HomeXilinx_PLANAHEAD = new javax.swing.JTextField();
        _lbl_HomeXilinx_PLANAHEAD = new javax.swing.JLabel();
        _btn_HomeXilinx_PLANAHEAD = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configuración Nessy");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        _lbl_HomeXilinx_ISE.setText("Home Xilinx ISE :");

        _txt_HomeXilinx_ISE.setText(rutaXilinxISE);
        _txt_HomeXilinx_ISE.setEditable(false);

        _btn_HomeXilinx_ISE.setText("Seleccion");
        _btn_HomeXilinx_ISE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btn_HomeXilinx_ISEActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Configuración");

        _btnOK.setText("OK");
        _btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnOKActionPerformed(evt);
            }
        });

        _btnCancelar.setText("Cancelar");
        _btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnCancelarActionPerformed(evt);
            }
        });

        _txt_HomeXilinx_EDK.setText(rutaXilinxEDK);
        _txt_HomeXilinx_EDK.setEditable(false);

        _lbl_HomeXilinx_EDK.setText("Home Xilinx EDK :");

        _btn_HomeXilinx_EDK.setText("Seleccion");
        _btn_HomeXilinx_EDK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btn_HomeXilinx_EDKActionPerformed(evt);
            }
        });

        _txt_HomeXilinx_PLANAHEAD.setText(rutaXilinxPLANAHEAD);
        _txt_HomeXilinx_PLANAHEAD.setEditable(false);

        _lbl_HomeXilinx_PLANAHEAD.setText("Home Xilinx PlanAhead :");

        _btn_HomeXilinx_PLANAHEAD.setText("Seleccion");
        _btn_HomeXilinx_PLANAHEAD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btn_HomeXilinx_PLANAHEADActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(18, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_lbl_HomeXilinx_PLANAHEAD, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(_lbl_HomeXilinx_ISE, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(_lbl_HomeXilinx_EDK, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(_txt_HomeXilinx_ISE, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_btn_HomeXilinx_ISE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(_txt_HomeXilinx_EDK)
                                    .addComponent(_txt_HomeXilinx_PLANAHEAD, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(_btn_HomeXilinx_PLANAHEAD)
                                    .addComponent(_btn_HomeXilinx_EDK)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(188, 188, 188)
                        .addComponent(_btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(67, 67, 67)
                        .addComponent(_btnCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(239, 239, 239)
                        .addComponent(jLabel1)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_txt_HomeXilinx_ISE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(_lbl_HomeXilinx_ISE)
                    .addComponent(_btn_HomeXilinx_ISE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_txt_HomeXilinx_EDK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(_lbl_HomeXilinx_EDK)
                    .addComponent(_btn_HomeXilinx_EDK))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_txt_HomeXilinx_PLANAHEAD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(_lbl_HomeXilinx_PLANAHEAD)
                    .addComponent(_btn_HomeXilinx_PLANAHEAD))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_btnCancelar)
                    .addComponent(_btnOK))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _btn_HomeXilinx_ISEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btn_HomeXilinx_ISEActionPerformed
        JFileChooser chooser;
        chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("C:/"));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Seleccionar Home Xilinx ISE");
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            rutaXilinxISE=chooser.getSelectedFile().getAbsolutePath();
            _txt_HomeXilinx_ISE.setText(rutaXilinxISE);
        } else {
            //log.info("Seleccion no llevada a cabo");
        }
    }//GEN-LAST:event__btn_HomeXilinx_ISEActionPerformed

    private void _btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnOKActionPerformed
        try {
            //TODO cargar configuracion en archivos.Properties prop = new Properties();
            InputStream is = null;
            Properties prop = new Properties();
            prop.setProperty("HomeXilinxISE", rutaXilinxISE);
            prop.setProperty("HomeXilinxEDK", rutaXilinxEDK);
            prop.setProperty("HomeXilinxPLANAHEAD", rutaXilinxPLANAHEAD);
            prop.store(new FileOutputStream("conf/config.properties"), "rutas");
            this.dispose();
        } catch (IOException ex) {
            System.out.println("Fallo");
        }
}//GEN-LAST:event__btnOKActionPerformed

    private void _btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnCancelarActionPerformed
        this.setVisible(false);
        this.dispose();
        
}//GEN-LAST:event__btnCancelarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
       cierre=true;
    }//GEN-LAST:event_formWindowClosing

    private void _btn_HomeXilinx_EDKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btn_HomeXilinx_EDKActionPerformed
        JFileChooser chooser;
        chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("C:/"));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Seleccionar Home Xilinx EDK");
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            rutaXilinxEDK=chooser.getSelectedFile().getAbsolutePath();
            _txt_HomeXilinx_EDK.setText(rutaXilinxEDK);
        } else {
            //log.info("Seleccion no llevada a cabo");
        }
    }//GEN-LAST:event__btn_HomeXilinx_EDKActionPerformed

    private void _btn_HomeXilinx_PLANAHEADActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btn_HomeXilinx_PLANAHEADActionPerformed
        JFileChooser chooser;
        chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("C:/"));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Seleccionar Home Xilinx PLANAHEAD");
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            rutaXilinxPLANAHEAD=chooser.getSelectedFile().getAbsolutePath();
            _txt_HomeXilinx_PLANAHEAD.setText(rutaXilinxPLANAHEAD);
        } else {
            //log.info("Seleccion no llevada a cabo");
        }
    }//GEN-LAST:event__btn_HomeXilinx_PLANAHEADActionPerformed

   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnCancelar;
    private javax.swing.JButton _btnOK;
    private javax.swing.JButton _btn_HomeXilinx_EDK;
    private javax.swing.JButton _btn_HomeXilinx_ISE;
    private javax.swing.JButton _btn_HomeXilinx_PLANAHEAD;
    private javax.swing.JLabel _lbl_HomeXilinx_EDK;
    private javax.swing.JLabel _lbl_HomeXilinx_ISE;
    private javax.swing.JLabel _lbl_HomeXilinx_PLANAHEAD;
    private javax.swing.JTextField _txt_HomeXilinx_EDK;
    private javax.swing.JTextField _txt_HomeXilinx_ISE;
    private javax.swing.JTextField _txt_HomeXilinx_PLANAHEAD;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

    boolean getCierre() {
      return cierre;
    }

}
